package core2.ch07awt;
import java.awt.Font;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.List;
//import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class HelloSwt {

	static List listLeft=null;
	static List listRight;
	static Shell shell;
	static Display display;
	static Button addBtn;
	static Button delBtn;
	static Button okBtn;
	static Button calBtn;
	
	public static void addWare() {
		if(listLeft.getItemCount()==0){
			return;
		}
		if(listLeft.getFocusIndex()==-1){
//			MessageBox.openInformation(
//					shell,
//					"����",
//					"��û��ѡ����ӵ�ѡ�");
			return;
		}
		listRight.add(listLeft.getItem(listLeft.getFocusIndex()));
		listLeft.remove(listLeft.getFocusIndex());

	}

	public static void delWare() {
		if(listRight.getItemCount()==0){
			return;
		}
		if(listRight.getFocusIndex()==-1){
//			MessageBox.openInformation(
//					shell,
//					"����",
//					"��û��ѡ����ӵ�ѡ�");
			return;
		}
		listLeft.add(listRight.getItem(listRight.getFocusIndex()));
		listRight.remove(listRight.getFocusIndex());
	}

	public static void main(String[] args) {
		Display display = new Display();
		shell = new Shell(display);

		shell.setBounds(200, 200, 500, 350);
		// Text helloText = new Text(shell, SWT.CENTER);
		// helloText.setText("Hello,World!");
		// helloText.setBounds(0,0,500,300);
		// helloText.pack();

		Group groupLeft = new Group(shell, SWT.NONE);
		groupLeft.setText("���з���"); //$NON-NLS-1$
		groupLeft.setBounds(40, 40, 180, 220);
		
		listLeft = new List(groupLeft, SWT.LEFT);
		listLeft.add("zzw");
		listLeft.add("zzw2");
		listLeft.setBounds(10, 20, 150, 190);

		Group groupRight = new Group(shell, SWT.NONE);
		groupRight.setText("���з���"); //$NON-NLS-1$
		groupRight.setBounds(290, 40, 180, 220);
		listRight = new List(groupRight, SWT.CENTER);
		listRight.add("zzw3");
		listRight.add("zzw4");
		listRight.setBounds(10, 20, 150, 190);

		addBtn = new Button(shell, SWT.NONE);
		addBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				addWare();// ����
			}
		});
		addBtn.setText("���");
		addBtn.setBounds(225, 100, 62, 22);

		delBtn = new Button(shell, SWT.NONE);
		delBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				delWare();// ����
			}
		});
		delBtn.setText("ɾ��");
		delBtn.setBounds(225, 200, 62, 22);

		okBtn = new Button(shell, SWT.NONE);
		okBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				addWare();// д���ļ�����
			}
		});
		okBtn.setText("ȷ��");
		okBtn.setBounds(75, 280, 62, 22);

		calBtn = new Button(shell, SWT.NONE);
		calBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				shell.dispose();
			}
		});
		calBtn.setText("ȡ��");
		calBtn.setBounds(325, 280, 62, 22);

		// shell.pack();
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();

	}
}
